/*
 * ========================================================
 * Copyright(c) 2014 杭州偶尔科技-版权所有
 * ========================================================
 * 本软件由杭州偶尔科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * 
 * 			http://www.kkkd.com/
 * 
 * ========================================================
 */
package com.simon.mengkou.ui.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.simon.mengkou.R;
import com.simon.mengkou.data.bean.base.Order;
import com.simon.mengkou.data.bean.base.Product;
import com.simon.mengkou.data.enums.EOrderStatus;
import com.simon.mengkou.system.global.OuerApplication;
import com.simon.mengkou.system.global.OuerDispatcher;
import com.simon.mengkou.ui.view.MyListView;
import com.simon.mengkou.utils.UtilOuer;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * @author : Zhenshui.Xia
 * @since : 2016/3/23.
 * desc    : 订单里的商品列表
 */
public class OrderProductAdapter extends AbsAdapter<Product> {

    public OrderProductAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        final Holder holder;
        if (null == convertView) {
            convertView = mInflater.inflate(R.layout.layout_my_order_product_item, null);
            holder = new Holder();
            convertView.setTag(holder);
            ButterKnife.bind(holder, convertView);
        } else {
            holder = (Holder) convertView.getTag();
        }

        final Product data = getItem(position);
        //图片
        OuerApplication.mImageLoader.loadImage(holder.mSdvImage, data.getImage().getUrl());
        holder.mSdvImage.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                OuerDispatcher.presentProductDetailActivity(mContext, data.getId());
            }
        });
        //标题
        holder.mTvTitle.setText(data.getTitle());
        //价格
        holder.mTvPrice.setText(mContext.getString(R.string.common_price,
                UtilOuer.formatPrice(data.getPrice())));
        //数量
        holder.mTvCount.setText(mContext.getString(R.string.common_multi, data.getCount()));
        return convertView;
    }


    /**
     * @author zhenshui.xia
     */
    class Holder {
        //图片
        @Bind(R.id.order_id_image)
        SimpleDraweeView mSdvImage;
        //标题
        @Bind(R.id.order_id_title)
        TextView mTvTitle;
        //价格
        @Bind(R.id.order_id_price)
        TextView mTvPrice;
        //数量
        @Bind(R.id.order_id_count)
        TextView mTvCount;

    }
}
